package eerbaar.client.internal.ctr.operator;

import eerbaar.client.ctr.OperatorConstants;
import eerbaar.client.exp.IExp;
import eerbaar.client.exp.IScope;
import eerbaar.client.internal.ctr.noun.Persona;
import eerbaar.client.internal.ctr.operator.area.ValueArea;
import eerbaar.elements.IElement;
import eerbaar.game.IGame;
import eerbaar.persona.IPersona;
import eerbaar.position.IPosition;

class RepelStrong extends AbstractExp {

    public RepelStrong(IExp[] array) {
        super(array);
    }

    @Override
    public void populateValueArea(IScope scope) {
        //
    }

    @Override
    public String toString() {

        return "" + super.getElementName() + OperatorConstants.REPEL_STRONG;
    }

    @Override
    public void updateArea(IScope scope) {

        if (super.getElementName() == null) {
            return;
        }

        IGame game = (IGame) scope.getGame();
        ValueArea area = (ValueArea) scope.getValueArea();

        IElement[] elements = game.getArea().getElements();
        for (IElement e : elements) {

            IElement target = (IElement) scope.getTarget();
            if (target.toString().equals(e.toString())) {
                continue;
            }

            String name = super.getElementName();
            if (name.equals(Persona.NAME) && (e instanceof IPersona)) {
                IPosition p = e.getPosition();
                area.decrement(p.getX(), p.getY(), -1000);
            }

            if (e.getName().equals(name)) {
                IPosition p = e.getPosition();
                area.decrement(p.getX(), p.getY(), -1000);
            }
        }
    }

}
